<template class="page">
   <base-view :model="query" @submit="search">
    <template>
      <a-col :span="8" v-show="query.instId!=''">
       <a-form-model-item label="批次日期" :labelCol="{span: 5}" >
       <a-date-picker  @change="value=>handlerChange(value,'batchDate')" v-model="query.batchDate"/>

      </a-form-model-item>
      </a-col>
      <a-col :span="16" v-show="query.instId!=''">
      <div v-show="query.instId!=''" style="text-align: center">
        <a-button type="primary" @click="search">查询</a-button>
        <a-button style="margin-left: 8px" @click="reset">重置</a-button>
      </div>
      </a-col>
    </template>
    <div class="section">
      <a-table
        ref="table"
        :columns="columns"
        :dataSource="dataSource"
        :rowKey="
          (record, index) => {
            return index;
          }
        "
        :loading="loading"
        :pagination="pagination"
        :scroll="{ x: 2000 }"
      >
        <template slot="operation" slot-scope="text, record">
          <a
            class="text-btn"
            v-has-permission="['eTppsErrTxn:update']"
            @click="edit(record)"
            >修改</a
          >
           <a-popconfirm
            title="确定要启用吗？"
            @confirm="cancel(record)"
            v-hasPermission="['eTppsErrTxn:update']"
            v-if="record.dstChannelStatus !== 'Y'"
          >
            <a class="text-btn danger">启用</a>
          </a-popconfirm>
          <a-popconfirm
            title="确定要停用吗？"
            @confirm="cancel(record)"
            v-hasPermission="['eTppsErrTxn:update']"
            v-if="record.dstChannelStatus !== 'N'"
          >
            <a class="text-btn danger">停用</a>
          </a-popconfirm>
          <a-popconfirm
            title="确定要注销吗？"
            @confirm="forbid(record)"
            v-hasPermission="['eTppsErrTxn:delete']"
            v-if="record.dstChannelStatus !== 'N'"
          >
            <a class="text-btn danger">注销</a>
          </a-popconfirm>
          <a
            class="text-btn"
            v-has-permission="['eTppsErrTxn:view']"
            @click="view(record)"
            >详情</a
          >
          <a
            class="text-btn"
            v-has-permission="['eTppsErrTxn:inport']"
            @click="exportExcel(record)"
            >导出</a
          >
          <a-badge
            status="warning"
            text="无权限"
            v-has-no-permission="['eTppsErrTxn:view', 'eTppsErrTxn:update','eTppsErrTxn:delete']"
          ></a-badge>
        </template>
      </a-table>
    </div>

     <a-modal
       v-model="modalVisible"
       :title="modalTitle"
       width="1050px"
       @ok="submit"
       :maskClosable="false"
       :footer="isHideFoot?null:undefined"
     >
       <e-tpps-err-txn-operation ref="modalForm" />
     </a-modal>
  </base-view>
</template>
<script>
import moment from "moment";
moment.locale('zh-cn');
import ETppsErrTxnOperation from './ETppsErrTxnOperation'
import {mapState} from "vuex";
export default {
  name: "ETppsErrTxn",
  components:{ETppsErrTxnOperation},
  data: function () {
    return {
      query: {
        instId: "",
        batchDate:null,
      },
      selectedRowKeys: [],
      beanInfo: {},
      modalVisible: false,
      isHideFoot: false,
      modalTitle: "",
      operationType: "add",
      loading: false,
      open:false,
      pagination: {
        pageSizeOptions: ["10", "20", "30", "40", "100"],
        defaultCurrent: 1,
        defaultPageSize: 10,
        showQuickJumper: true,
        showSizeChanger: true,
        showTotal: (total, range) =>
          `显示 ${range[0]} ~ ${range[1]} 条记录，共 ${total} 条记录`,
      },
      columns: [
        {
          title: "机构标识",
          dataIndex: "instId",
          width:150,
          fixed:'left'
        },
        {
          title: "批次日期",
          dataIndex: "batchDate",
          width:150,
        },
         {
          title: "任务参数",
          dataIndex: "taskParam",
          width:150,
        },
         {
          title: "批次号",
          dataIndex: "batchNo",
          width:150,
        },
         {
          title: "原子任务号",
          dataIndex: "atomTaskId",
          width:260,
        },
        {
          title: "业务产品类型",
          dataIndex: "bizProdType",
          width:200,
           customRender:(text,row)=>{
            return text ? {
              "01" : '银联CUPS受理侧',
              "02" : '微信支付',
              "03" : '支付宝支付',
              "04" : '分期',
              "05" : '积分',
              "06" : '银联小微二维码',
              "07" : '网联受理侧',
              "08" : '本行渠道业务',
              "11" : '银联助农业务',
              "21" : '银联线上支付',
              "22" : '银联无卡快捷受理侧支付业务',
              "32" : '银联无卡快捷代付业务',
              "33" : '银联无卡快捷代收业务',
              "23" : '银联全渠道_代付业务',
              "24" : '银联全渠道_无跳转业务',
              "25" : '银联全渠道_代收业务',
              "26" : '深圳银联业务',
              "27" : '厦门银联业务',
              "31" : '银联二维码',
              "34" : '银联网关支付',
              "40" : '提现',
              "45" : '营销',
              "90" : '银联CUPS发卡侧',
              "91" : '网联发卡侧',
              "92" : '银联无卡快捷发卡侧',
              "41" : '商户入账失败挂账',
              "42" : '风险资金挂账',
              "43" : '商户风险资金入账失败挂账',
              "46" : 'D0补入账',
              "47" : '虚拟账户业务',
              "48" : '人行大小额',
              "49" : '超级网银',
              "44" : '代理商分润',
              "50" : '中金支付',
              "51" : 'D1垫资资金回填',
              "52" : '连锁商户入账',
              "53" : '内部户记账',
              "60" : '本行渠道D0业务',
              "61" : '银联CUPS受理侧D0业务',
              "62" : '微信支付D0业务',
              "63" : '支付宝支付D0业务',
              "64" : '银联无卡快捷受理侧支付D0业务',
              "65" : '银联全渠道_无跳转D0业务',
              "66" : '银联网关支付D0业务',
              "67" : '银联二维码D0业务',
              "*"  : '所有业务',
            }[text]:""
          }
        },
        {
          title: "自动调账标志",
          dataIndex: "autoAdjustFlag",
          width:150,
           customRender:(text,row)=>{
            return text ? {
              "1":"自动调账",
              "2":"手工调账",
            }[text]:""
          }
        },
        {
          title: "原交易关键域",
          dataIndex: "origKey",
          width:150,
        },
        {
          title: "关联交易关键域",
          dataIndex: "relationKey",
          width:260,
        },
        {
          title: "交易码",
          dataIndex: "txnNum",
          width:150,
        },
        {
          title: "差错类型",
          dataIndex: "errType",
          width:150,
        },
        {
          title: "差错原因码",
          dataIndex: "errReasonCode",
          width:150,
        },
        {
          title: "交易金额",
          dataIndex: "transAmt",
          width:150,
        },
        {
          title: "交易币种",
          dataIndex: "transCcy",
          width:150,
        },
        {
          title: "差错提交时间",
          dataIndex: "errCommitTime",
          width:150,
        },
        {
          title: "差错清算时间",
          dataIndex: "errSettleTime",
          width:150,
        },
        {
          title: "通道费用",
          dataIndex: "payChannelFee",
          width:150,
        },
        {
          title: "差错服务费",
          dataIndex: "errServiceFee",
          width:150,
        },
        {
          title: "发起方备注",
          dataIndex: "initiatorRemark",
          width:150,
        },
        {
          title: "受理方备注",
          dataIndex: "acqRemark",
          width:150,
        },
        {
          title: "差错原因描述",
          dataIndex: "errDesc",
          width:150,
        },
        {
          title: "差错状态",
          dataIndex: "errStatus",
          width:150,
        },
        {
          title: "自动调账失败处理",
          dataIndex: "autoAdjustFailDeal",
          width:150,
          customRender:(text)=>{
            return text ? {
              "0" : '不处理',
              "1" : '转成手工调账',
            }[text]:""
          }
        },
        {
          title: "调账状态",
          dataIndex: "adjustStatus",
          width:150,
          customRender:(text)=>{
            return text ? {
              "00" : '未调账',
              "01" : '调账中',
              "02" : '调账成功',
              "03" : '调账失败',
            }[text]:""
          }
        },
        {
          title: "处理状态",
          dataIndex: "acctStatus",
          width:150,
          customRender:(text)=>{
            return text ? {
              "00" : '待记账',
              "01" : '记账成功',
              "02" : '记账失败',
            }[text]:""
          }
        },
        {
          title: "复核人代号",
          dataIndex: "auditOprId",
          width:150,
        },
        {
          title: "审核状态",
          dataIndex: "auditStatus",
          width:150,
          customRender:(text)=>{
            return text ? {
              "00" : '待提交审批',
              "11" : '注销待审核',
              "22" : '停用审核通过',
              "33" : '启用审核拒绝',
              "01" : '新增待审核',
              "12" : '注销审核通过',
              "23" : '停用审核拒绝',
              "02" : '新增审核通过',
              "13" : '注销审核拒绝',
              "03" : '新增审核拒绝',
              "41" : '修改待审核',
              "31" : '启用待审核',
              "42" : '修改审核通过',
              "21" : '停用待审核',
              "32" : '启用审核通过',
              "43" : '修改审核拒绝',
            }[text]:""
          }
        },
        {
          title: "操作",
          fixed: "right",
          scopedSlots: { customRender: "operation" },
        },
      ],
      dataSource: [],
    };
  },


  computed: {
    ...mapState({
      user: state => state.account.user,
    })

  },

  methods: {

    reset() {
      // 取消选中
      this.selectedRowKeys = []
      // 重置分页
      this.$refs.table.pagination.current = this.pagination.defaultCurrent
      if (this.paginationInfo) {
        this.paginationInfo.current = this.pagination.defaultCurrent
        this.paginationInfo.pageSize = this.pagination.defaultPageSize
      }
      // 重置查询参数
      this.query = {}
      // // 清空时间选择
      // this.$refs.createTime.reset()
      // this.search()
    },

    mchntChange(value) {
      this.query.merchantNo = value;
    },
    handlerChange(value,item){
      console.log(moment(value).format('YYYYMMDD')+'当前时间---')
      value = moment(value).format('YYYYMMDD');

      this.query.batchDate = value
      console.log(this.query.batchDate+"       ***")

    },
    handlerSearch(item){},
    industryTypeChange(value) {
      this.query.industryType = value;
    },
    industryTypeSearch(item){},

    async search(e) {
      e && e.preventDefault && e.preventDefault();
      console.log( this.query.instId+"    *"+this.query.batchDate)
      try {
        const res = await this.$get("/admin/igas/eTppsErrTxn/findByPage", {
          instId: this.query.instId,
          userId:this.user.userId,
          batchDate: this.query.batchDate,
          pageNum: this.pagination.defaultCurrent,
          pageSize: this.pagination.defaultPageSize,
        });
        console.log(res.data.rows+"   ******调用.....")
        this.dataSource = res.data.rows;
        this.$set(this.pagination, "total", +res.data.total);
      } catch (e) {
        console.error(e);
      }
    },
    openModal(type = "view", beanInfo) {
      this.modalTitle = {
        add: "新增",
        edit: "编辑",
        view: "详情",
        delete: "注销",
      }[type];
      this.modalVisible = true;
      if(type === 'view'){
        this.isHideFoot = true;
      }else{
        this.isHideFoot = false
      }
      this.$nextTick(() => {
        this.$refs.modalForm.setOperatorType(type);
        if (type === "edit" || type === "view" || type === "delete") {
          console.log(beanInfo.primaryKey+"               ****** beanInfo ")
          this.$refs.modalForm.setBeanInfo(beanInfo);
        }
        this.$refs.modalForm.resetFields(this.query.instId);
      });
    },
    async submit() {
      const res = await this.$refs.modalForm.submit();
      if (res) {
        this.modalVisible = false;
        this.pagination.defaultCurrent = 1;
        await this.search();
      }
    },
    async add(item) {
      this.openModal("add", item);
    },
    async edit(item) {
      this.openModal("edit", item);
    },
    view(item) {
      this.openModal("view", item);
    },

   async cancel (item) {
      try {
        const res = await this.$post('/admin/igas/pTxnCfg/changeStatus',
        {
          txnNum: item.txnNum,
          bizType: item.bizType,
          txnGroup: item.txnGroup,
          bizProdCode: item.bizProdCode,
          supportFlag: item.supportFlag==='N'?'Y':'N'})
        if (res.status === 200) {
          this.$message.success('操作成功')
          this.pagination.defaultCurrent = 1
          await this.search()
        }
      } catch (e) {
        console.error(e)
      }
    },
    async forbid(item) {
      if (item.agentStatus === "03") {
        return this.$message.warning("已注销数据不允许重复注销");
      }
      this.openModal("delete", item);
    },
    exportExcel(item){},

/*     handleClose() {
      this.open = false;
    },*/
  },
  mounted() {
    // this.search();
  },
};
</script>
<style lang="less" scoped>
@import "../../../../../static/less/Common";
.page {
  width: 100%;
}

.section {
  background: #fff;
}

.form {
  text-align: center;
}
.select {
  width: 180px;
}

.btn-group {
  margin-bottom: 20px;
}
.subtitle{
  width: 100%;
  font-size: 16px;
  margin-bottom: 10px;
  padding: 0 10px;
}
a-form-model-item{
   width: 50%;
  padding-left: 10px;
  padding-right: 10px;
}
/deep/.ant-select-selection--single{
  min-width: 200px;
}
/deep/.search{
  flex: content;
  width: 100%;
}
 /deep/.ant-form-item > .ant-form-item-label {
    display: inline-block;
    vertical-align: top;
    min-width: 120px;}
/deep/ .ant-form-item-control {
    position: relative;
    line-height: 40px;
    zoom: 1;
    min-width: 200px;
    }
</style>
